﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using DigitalPlatform.Common.Event;
using DigitalPlatform.Models;
using DigitalPlatform.Models.MenuModels;
using HandyControl.Interactivity;
using Prism.Commands;
using Prism.Events;
using Prism.Regions;
using Unity;

namespace DigitalPlatform.ViewModels
{
    public class MainViewModel
    {
        [Dependency]
        public IEventAggregator _eventAggregator { get; set; }
        [Dependency]
        public IRegionManager _iregionmanager { get; set; }

        public MainViewModel(IRegionManager manager)
        {
            _iregionmanager = manager;
            init();
        }

        #region init
        private void init()
        {
            bnmin = new DelegateCommand<object>(bnmin_func);
            bnmax = new DelegateCommand<object>(bnmax_func);
            bnclose = new DelegateCommand<object>(bnclose_func);
            bnselect = new DelegateCommand<object>(bnselect_func);
            MenuList = new ObservableCollection<MenuModel>();
            #region addmenu
            MenuList.Add(new MenuModel()
            {
                IsSelected = true,
                MenuHeader = "监视",
                MenuIcon = "\ue69e",
                TargetView = "MonitorPage"
            });
            MenuList.Add(new MenuModel()
            {
                MenuHeader = "趋势",
                MenuIcon = "\ue756",
                TargetView = "TrendPage"
            });
            MenuList.Add(new MenuModel()
            {
                MenuHeader = "报警",
                MenuIcon = "\ue612",
                TargetView = "AlarmPage"
            });
            MenuList.Add(new MenuModel()
            {
                MenuHeader = "报表",
                MenuIcon = "\ue65d",
                TargetView = "ReportPage"
            });
            MenuList.Add(new MenuModel()
            {
                MenuHeader = "配置",
                MenuIcon = "\ue600",
                TargetView = "SettingsPage"
            });
            #endregion
            _iregionmanager.RegisterViewWithRegion("MainPanel", "MonitorPage");
        }
        #endregion
        #region properites
        //菜单列表
        public ObservableCollection<MenuModel> MenuList { get; set; }
         
        #endregion

        #region command
        public DelegateCommand<object> bnmin { get; set; }
        public DelegateCommand<object> bnmax { get; set; }
        public DelegateCommand<object> bnclose { get; set; }
        public DelegateCommand<object> bnselect { get; set; }
        #endregion

        #region func
        /// <summary>
        /// 当菜单栏任意一项按下执行
        /// </summary>
        /// <param name="obj"></param>
        public void bnselect_func(object obj)
        {
            var model = obj as MenuModel;
            if (model != null) //导航到指定界面
                _iregionmanager.RequestNavigate("MainPanel", model.TargetView);

        }


        public void bnmin_func(object obj)
        {
            _eventAggregator.GetEvent<Event_MinMainWindow>().Publish();
        }
        public void bnmax_func(object obj)
        {
            _eventAggregator.GetEvent<Event_MaxMainWindow>().Publish();
        }
        public void bnclose_func(object obj)
        {
            _eventAggregator.GetEvent<Event_CloseMainWindow>().Publish();
        }
        #endregion
    }
}
